package com.example.pongv1;

import org.andengine.entity.scene.menu.MenuScene;
import org.andengine.entity.scene.menu.MenuScene.IOnMenuItemClickListener;
import org.andengine.entity.scene.menu.item.IMenuItem;
import org.andengine.entity.scene.menu.item.SpriteMenuItem;
import org.andengine.entity.scene.menu.item.decorator.ScaleMenuItemDecorator;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.text.Text;
import org.andengine.entity.text.TextOptions;
import org.andengine.util.HorizontalAlign;

import com.example.pongv1.Constantes.LEVEL;
import com.example.pongv1.SceneManager.SceneType;

public class InfoScene extends BaseScene implements IOnMenuItemClickListener,Constantes {

	private MenuScene optionChildScene;
	private final int reset = 0;
	private IMenuItem resetItem;
	
	


	@Override
	public void createScene() {
		createBackground();
		initscene();
		
	}

	@Override
	public void onBackKeyPressed() {
		SceneManager.getInstance().loadMenuScene();
		
	}

	@Override
	public SceneType getSceneType() {
		return SceneType.SCENE_INFO;
	}

	@Override
	public void disposeScene() {
		RessourcesManager.getInstance().unloadOptionTextures();
		
	}
	
	private void initscene(){
		 optionChildScene = new MenuScene(camera);
		    optionChildScene.setPosition(400, 240);
		    
		    //mise en page des options
		   Text soloText = new Text(optionChildScene.getX()-camera.getWidth(), optionChildScene.getY()-camera.getHeight(), ressourcesManager.font, "Solo:", new TextOptions(HorizontalAlign.CENTER), ressourcesManager.vbom);
		   Text lineText = new Text(optionChildScene.getX()-camera.getWidth(), optionChildScene.getY()-camera.getHeight()+80, ressourcesManager.font, "----------------------------------------", new TextOptions(HorizontalAlign.CENTER), ressourcesManager.vbom);
		   lineText.setColor(0.9f,0.5f,0.2f);
		   Text multiText = new Text(optionChildScene.getX()-camera.getWidth(), optionChildScene.getY()-camera.getHeight()+120, ressourcesManager.font, "Multi:", new TextOptions(HorizontalAlign.CENTER), ressourcesManager.vbom);
		   Text lineText1 = new Text(optionChildScene.getX()-camera.getWidth(), optionChildScene.getY()-camera.getHeight()+340, ressourcesManager.font, "----------------------------------------", new TextOptions(HorizontalAlign.CENTER), ressourcesManager.vbom);
		   lineText1.setColor(0.9f,0.5f,0.2f);
		   Text IsololevelText = new Text(optionChildScene.getX()-camera.getWidth()+10, optionChildScene.getY()-camera.getHeight()+50, ressourcesManager.font2, "Highest IA level:", new TextOptions(HorizontalAlign.CENTER), ressourcesManager.vbom);
		   Text IrankText = new Text(optionChildScene.getX()-camera.getWidth()+10, optionChildScene.getY()-camera.getHeight()+200, ressourcesManager.font2, "Rank:", new TextOptions(HorizontalAlign.CENTER), ressourcesManager.vbom);
		   Text InbvsucText = new Text(optionChildScene.getX()-camera.getWidth()+450, optionChildScene.getY()-camera.getHeight()+240, ressourcesManager.font2, "Serials wins:", new TextOptions(HorizontalAlign.CENTER), ressourcesManager.vbom);
		   Text InbvtotText = new Text(optionChildScene.getX()-camera.getWidth()+450, optionChildScene.getY()-camera.getHeight()+300, ressourcesManager.font2, "Total wins:", new TextOptions(HorizontalAlign.CENTER), ressourcesManager.vbom);
		   Text InblostText = new Text(optionChildScene.getX()-camera.getWidth()+450, optionChildScene.getY()-camera.getHeight()+180, ressourcesManager.font2, "Total defeats:", new TextOptions(HorizontalAlign.CENTER), ressourcesManager.vbom);
		   Text IhighrankpersoText = new Text(optionChildScene.getX()-camera.getWidth()+10, optionChildScene.getY()-camera.getHeight()+280, ressourcesManager.font2, "Top rank:", new TextOptions(HorizontalAlign.CENTER), ressourcesManager.vbom);
		 

		   
		  resetItem = new ScaleMenuItemDecorator(new SpriteMenuItem(reset, ressourcesManager.reset_region, vbom), 1.2f, 1);
		   

		   optionChildScene.attachChild(soloText);
			optionChildScene.attachChild(multiText);
			optionChildScene.attachChild(lineText);
			optionChildScene.attachChild(lineText1);
			optionChildScene.attachChild(IsololevelText);
			optionChildScene.attachChild(IrankText);
			optionChildScene.attachChild(InbvsucText);
			optionChildScene.attachChild(InbvtotText);
			optionChildScene.attachChild(InblostText);
			optionChildScene.attachChild(IhighrankpersoText);
			
			 
			   Text IRsololevelText = new Text(optionChildScene.getX()-camera.getWidth()+IsololevelText.getWidth()+20, optionChildScene.getY()-camera.getHeight()+40, ressourcesManager.font4,ressourcesManager.nialevel, new TextOptions(HorizontalAlign.CENTER), ressourcesManager.vbom);
			  Text IRrankText = new Text(optionChildScene.getX()-camera.getWidth()+IrankText.getWidth()+20, optionChildScene.getY()-camera.getHeight()+190, ressourcesManager.font4, ressourcesManager.nrank, new TextOptions(HorizontalAlign.CENTER), ressourcesManager.vbom);
			  Text IRnbvsucText = new Text(optionChildScene.getX()-camera.getWidth()+450+InbvsucText.getWidth()+35, optionChildScene.getY()-camera.getHeight()+230, ressourcesManager.font4,ressourcesManager.nSerialswins, new TextOptions(HorizontalAlign.CENTER), ressourcesManager.vbom);
			   Text IRnbvtotText = new Text(optionChildScene.getX()-camera.getWidth()+450+InbvtotText.getWidth()+50, optionChildScene.getY()-camera.getHeight()+290, ressourcesManager.font4,  ressourcesManager.ntotwin, new TextOptions(HorizontalAlign.CENTER), ressourcesManager.vbom);
			   Text IRnblostText = new Text(optionChildScene.getX()-camera.getWidth()+450+InblostText.getWidth()+15, optionChildScene.getY()-camera.getHeight()+170, ressourcesManager.font4,  ressourcesManager.ntotdefeat, new TextOptions(HorizontalAlign.CENTER), ressourcesManager.vbom);
			   Text IRhighrankpersoText = new Text(optionChildScene.getX()-camera.getWidth()+10+IhighrankpersoText.getWidth()+10, optionChildScene.getY()-camera.getHeight()+270, ressourcesManager.font4,  ressourcesManager.ntoprank, new TextOptions(HorizontalAlign.CENTER), ressourcesManager.vbom);
			  
			optionChildScene.attachChild(IRsololevelText);
			optionChildScene.attachChild(IRrankText);
			optionChildScene.attachChild(IRnbvsucText);
			optionChildScene.attachChild(IRnbvtotText);
			optionChildScene.attachChild(IRnblostText);
			optionChildScene.attachChild(IRhighrankpersoText);
			
			
		   
		    optionChildScene.addMenuItem(resetItem);
		    
		    optionChildScene.buildAnimations();
		    optionChildScene.setBackgroundEnabled(false);
		    
		   
	     resetItem.setPosition(optionChildScene.getX()-camera.getWidth()+(camera.getWidth()/2-resetItem.getWidth()/2), optionChildScene.getY()-camera.getHeight()+380);
	   
	     optionChildScene.setOnMenuItemClickListener(this);
	     		    
		    setChildScene(optionChildScene);
		   
		 
		
}
	
	
	private void createBackground()
	{
		attachChild(new Sprite(-CAMERA_WIDTH/2,-CAMERA_HEIGHT/2, ressourcesManager.info_background_region, vbom));
}


	@Override
	public boolean onMenuItemClicked(MenuScene pMenuScene, IMenuItem pMenuItem,
			float pMenuItemLocalX, float pMenuItemLocalY) {
		 switch(pMenuItem.getID())
	        {
	        case reset:
	        	initinfos();
	            return true;
	        
	        default:
	            return false;
	    }
	}

	public void initinfos(){
		ressourcesManager.nialevel="None";
		ressourcesManager.nrank="Rookie";
		ressourcesManager.nSerialswins="0";
		ressourcesManager.ntotwin="0";
		ressourcesManager.ntotdefeat="0";
		ressourcesManager.ntoprank="Rookie";
		initscene();
	
	}
}
